package router 

import (
	"net/http"
	"github.com/gin-gonic/gin"
	"yigin/controller"
    "github.com/gin-contrib/sessions"
    "github.com/gin-contrib/sessions/cookie"
)

func InitRouter() *gin.Engine {
	r := gin.Default()

	gin.SetMode("debug")
    //定义加密
    store := cookie.NewStore([]byte("secret"))

    //绑定session中间件
    r.Use(sessions.Sessions("mysession", store))
	r.NoRoute(func(c *gin.Context) {
        c.JSON(
            http.StatusOK,
            gin.H{
                "code":  http.StatusOK,
                "error": "404,is error router",
            },
        )
	})
	r.LoadHTMLGlob("views/*")

	web := r.Group("")
	{
		web.GET("/admin", controller.AdminIndex)
		web.GET("/login", controller.Login)
		web.GET("/logout", controller.LogOut)
	}

	return r
}